<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>客户端</title>
</head>
<body>
M
</body>
<script src="socket.io.js"></script>
<script type="text/javascript">
    const serverUri = "http://127.0.0.1:10246";
    const sendEvent = "ServerReceive";
    const receiveEvent = "ClientReceive";

    var socket;

    connect(1001);

    function connect(uid) {
        socket = io.connect(serverUri, {
            'force new connection': true,
            'query': 'UID=' + uid
        });
        socket.on('connect', function () {
            console.log("连接成功");
            //如果发送字符串send("hello Server"); *需要修改服务端接收类型
            send({
                name: "client",
                message: "hello Server"
            });
        });
        socket.on(receiveEvent, function (data) {
            console.log(data);
        });
        socket.on('disconnect', function () {
            console.log("连接断开");
        });
    }

    function send(data) {
        socket.emit(sendEvent, data);
    }
</script>
</html>